import { message } from 'antd';
import api from '../../api';
export default {
  namespace: 'nonstandardCurveMapM',
  state: {},

  effects: {
    // 折线曲线页面新建编辑表格数据
    *addData({ payload, callback }, { call, put }) {
      const response = yield call(api.nonstandardCurveMap.addData, payload);
      if (response && response.code == 0) {
        callback(response);
      } else {
        callback();
        message.error(`保存失败，失败原因：${response?.msg}`);
        console.error(`保存失败，失败原因：${response?.msg}`, '接口名称： saveOrUpdate 接口：portfolio-server/nonstandarCurve/saveOrUpdate');
      }
    },

    // 折线曲线默认页面查询表格数据
    *getDefaultData({ payload, callback }, { call, put }) {
      const response = yield call(api.nonstandardCurveMap.getDefaultData, payload);
      if (response && response.code == 0) {
        callback(response);
      } else {
        callback();
        message.error(`查询失败，失败原因：${response?.msg}`);
        console.error(`查询失败，失败原因：${response?.msg}`, '接口名称： getDefaultList 接口：portfolio-server/nonstandarCurve/getDefaultList');
      }
    },

    // 折线曲线默认页面删除表格数据
    *deleteDefaultData({ payload, callback }, { call, put }) {
      const response = yield call(api.nonstandardCurveMap.deleteDefaultData, payload);
      if (response && response.code == 0) {
        callback(response);
      } else {
        callback();
        message.error(`删除失败，失败原因：${response?.msg}`);
        console.error(`删除失败，失败原因：${response?.msg}`, '接口名称： deleteDefault 接口：portfolio-server/nonstandarCurve/deleteDefault');
      }
    },

    // 折线曲线特定页面查询表格数据
    *getSpecificData({ payload, callback }, { call, put }) {
      const response = yield call(api.nonstandardCurveMap.getSpecificData, payload);
      if (response && response.code == 0) {
        callback(response);
      } else {
        callback();
        message.error(`查询失败，失败原因：${response?.msg}`);
        console.error(`查询失败，失败原因：${response?.msg}`, '接口名称： getSpecificList 接口：portfolio-server/nonstandarCurve/getSpecificList');
      }
    },

    // 折线曲线特定页面删除表格数据
    *deleteSpecificData({ payload, callback }, { call, put }) {
      const response = yield call(api.nonstandardCurveMap.deleteSpecificData, payload);
      if (response && response.code == 0) {
        callback(response);
      } else {
        callback();
        message.error(`删除失败，失败原因：${response?.msg}`);
        console.error(`删除失败，失败原因：${response?.msg}`, '接口名称： deleteSpecific 接口：portfolio-server/nonstandarCurve/deleteSpecific');
      }
    },

    //曲线下拉数据
    *getCurveData({ payload, callback }, { call, put }) {
      const response = yield call(api.nonstandardCurveMap.getCurveData, payload);
      if (response && response.code == 0) {
        callback(response);
      } else {
        callback();
        message.error(`获取曲线数据失败，失败原因：${response?.msg}`);
        console.error(`获取曲线数据失败，失败原因：${response?.msg}`, '接口名称： getCurves 接口：portfolio-server/nonstandarCurve/getCurves');
      }
    },
  },
  reducers: {
    save(state, { payload }) {
      return { ...state, ...payload };
    },
  },
};
